home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <conio.h>
- #include <iostream.h>
- #include "pxengine.h"
-
- #define TABLENAME "datesort"
- #define PXErr(param) PXError(__FILE__, __LINE__, param)
-
- int PXError (char*, int, int);
- int GlobalPXErr;
- unsigned _stklen = 30000;
-
- int main(void)
- {
- TABLEHANDLE tblHandle;
- RECORDHANDLE recHandle;
- FIELDHANDLE fldHandles[] = {2};
- RECORDNUMBER r;
- int pxErr,day,month,year;
- int i; //watch i in TD to see return values
- DATE date;
-
- PXErr(PXInit());
- PXErr(PXKeyAdd(TABLENAME,1,fldHandles,PRIMARY)); //p-index set on NAME
- PXErr(PXKeyAdd(TABLENAME,1,fldHandles,INCSECONDARY));//s-index on B-DAY
- // PXErr(PXTblOpen(TABLENAME, &tblHandle, 0, 0)); //open table on primary
- PXErr(PXTblOpen(TABLENAME, &tblHandle, 2, 0)); //open on secondary
-
- PXErr(PXRecBufOpen(tblHandle, &recHandle));
- PXErr(PXRecFirst(tblHandle)); //move cursor to top of table
-
- for (int j = 1; j < 5; j++) //table has 5 records
- {
- PXErr(PXRecGet(tblHandle,recHandle)); //load record buffer
- PXErr(PXGetDate(recHandle,2,&date)); //get date from buffer
- PXErr(PXDateDecode(date,&month,&day,&year));
- cout<<"Date in record #"<<j<<" is "<<month<<" "<< day<<" "<< year<<endl;
- if ( j != 4 ) PXErr(PXRecNext(tblHandle)); //move down 1 record
- }
-
- PXErr(PXDateEncode(2,3,66,&date));
- PXErr(PXPutDate(recHandle,2,date)); //load record buffer w/date
- PXErr(PXSrchFld(tblHandle,recHandle,2,CLOSESTRECORD)); //search
- PXErr(PXRecNum(tblHandle,&r)); //get rec number
- PXErr(PXRecGet(tblHandle,recHandle)); //load record buffer
- PXErr(PXGetDate(recHandle,2,&date)); //get date from buffer
- PXErr(PXDateDecode(date,&month,&day,&year));
- cout<<"Closest value to 2 3 66 is located in "
- <<"record #"<<r <<": "<<month<<" "<< day<<" "<< year<<endl;
-
-
- PXErr(PXTblClose(tblHandle));
- PXErr(PXKeyDrop(TABLENAME,0));
- PXErr(PXExit());
- return 0;
- }
-
- int PXError(char* module, int line, int retval)
- {
- if (retval == PXSUCCESS)
- {
- GlobalPXErr = PXSUCCESS;
- return retval;
- }
- cout<<"module: "<<module<<" line: "<<line<<" error#: "<<retval<<endl;
- cout<<"\""<<PXErrMsg(retval)<<"\""<<endl;
- GlobalPXErr = retval;
- return retval;
- }
-